import React, { Component } from 'react'
import { Button, FlatList, Text, View,Image } from 'react-native'
let url="http://johnu.cn/s183/"
export default class Home extends Component {
  state={stus:[]}
  componentDidMount(){
    this.props.navigation.addListener('focus',()=>{
        alert("dddd")
    })
    fetch("http://172.20.10.2:3000/stus")
    .then(resp=>resp.json())
    .then(stus=>{
      console.log(stus)
      this.setState({stus})
    })
  }
  
  _add=()=>{
    this.props.navigation.navigate('StuAddor')
  }
  _renderStu=({item})=><View>
  <Text>{item.name}</Text>
  <Image style={{width:200,height:200}} source={{uri:"http://39.100.242.209/s183/"+item.img}}/>
  </View>
  render() {
    return (
      <View>
        <Button title="添加" onPress={this._add}/>
        <FlatList data={this.state.stus} renderItem={this._renderStu} keyExtractor={stu=>stu.id}/>
      </View>
    )
  }
}
